using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using Learn.Web.MVC.Code;
using System.Reflection;
using System.Diagnostics;
using Learn.Web.MVC.Models;

namespace Learn.Web.MVC.Controllers
{
    public class ProductController : Controller
    {
        //
        // GET: /Product/
        //[MyActionFilter(Name = "Filter1", Order = 1)]
        //[MyActionFilter(Name = "Filter2", Order = 2)]
        //[MyActionFilter(Name = "Filter3", Order = 3)]
        public ActionResult Index()
        {
            Response.Write("Acction Method!<br/>");
            //MethodBase method = new StackFrame(1).GetMethod();
            //Response.Write(string.Format("MethodName:{0}--ModuleName:{1}<br/>", method.Name, method.Module));
            ViewData["t1"] = "t1 value";

            List<ProductInfoModel> list = new List<ProductInfoModel>();
            list.Add(new ProductInfoModel {  ID=1,Name="A"});
            list.Add(new ProductInfoModel { ID = 2, Name = "B" });
            list.Add(new ProductInfoModel { ID = 3, Name = "C" });

            ViewData["products"] = list;

            return View();
        }

        //
        // GET: /Product/Details/5

        public ActionResult Details(int id)
        {
            

            return View();
        }

        //
        // GET: /Product/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Product/Create

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Product/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Product/Edit/5

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
                
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
